import 'package:intl/intl.dart';

class Cert {
  String id;
  String userId;
  String certType;
  String certName;
  String certNumber;
  String certAuthority;

  DateTime certStartTime;
  DateTime certEndTime;
  DateTime certOpenDate;
  DateTime certSecondTime;

  String realname;
  String deptName;
  String specialty;
  String craft;
  String level;
  String skillLevel;
  String remark;

  String photoFront;
  String photoBack;

  DateFormat format = new DateFormat('yyyy-MM-dd');

  Cert({
    this.id,
    this.userId,
    this.certType,
    this.certName,
    this.certNumber,
    this.certAuthority,
    this.certStartTime,
    this.certEndTime,
    this.certOpenDate,
    this.certSecondTime,
    this.realname,
    this.deptName,
    this.specialty,
    this.craft,
    this.level,
    this.skillLevel,
    this.remark,
    this.photoFront,
    this.photoBack,
  });

  static Cert fromJson(Map<String, dynamic> json) {
    return Cert(
      id: json['id'],
      userId: json['userId'],
      certType: json['certType'],
      certName: json['certName'],
      certNumber: json['certNumber'],
      certAuthority: json['certAuthority'],
      realname: json['realname'],
      deptName: json['deptName'],
      specialty: json['specialty'],
      craft: json['craft'],
      level: json['level'],
      skillLevel: json['skillLevel'],
      remark: json['remark'],
      photoFront: json['photoZ'],
      photoBack: json['photoF'],
      certStartTime: json['certStartTime'] == null ? null : DateTime.parse(json['certStartTime']),
      certEndTime: json['certEndTime'] == null ? null : DateTime.parse(json['certEndTime']),
      certOpenDate: json['certOpenDate'] == null ? null : DateTime.parse(json['certOpenDate']),
      certSecondTime: json['certSecondTime'] == null ? null : DateTime.parse(json['certSecondTime']),
    );
  }

  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      'id': this.id,
      'userId': this.userId,
      'certType': this.certType,
      'certName': this.certName,
      'certNumber': this.certNumber,
      'certAuthority': this.certAuthority,
      'realname': this.realname,
      'deptName': this.deptName,
      'specialty': this.specialty,
      'craft': this.craft,
      'level': this.level,
      'skillLevel': this.skillLevel,
      'remark': this.remark,
      'photoZ': this.photoFront,
      'photoF': this.photoBack,
      'certStartTimeStr': formatDate(this.certStartTime),
      'certEndTimeStr': formatDate(this.certEndTime),
      'certOpenDateStr': formatDate(this.certOpenDate),
      'certSecondTimeStr': formatDate(this.certSecondTime),
    };
  }

  String formatDate(DateTime dateTime) {
    if (dateTime == null) return null;
    return format.format(dateTime);
  }
}

class CertProfile {
  String id;
  String certName;
  String certType;
  String certNumber;
  DateTime certStartTime;
  DateTime certEndTime;

  CertProfile({
    this.id,
    this.certName,
    this.certType,
    this.certNumber,
    this.certStartTime,
    this.certEndTime,
  });

  static CertProfile fromJson(Map<String, dynamic> json) {
    return CertProfile(
      id: json['id'],
      certName: json['certName'],
      certType: json['certType'],
      certNumber: json['certNumber'],
      certStartTime: json['certStartTime'] == null ? null : DateTime.parse(json['certStartTime']),
      certEndTime: json['certEndTime'] == null ? null : DateTime.parse(json['certEndTime']),
    );
  }
}
